CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


  GYRO_SDA      = 3
  GYRO_SCL      = 5

  X             = 0
  Y             = 1
  Z             = 2
  AVG_COUNT     = 100

var


obj

  d     :       "Parallax Serial Terminal"
  gyro  :       "Gyro_L3G4200D"

pub go | val[3], off[3], acc[3], i, t

  d.start(115_200)

  gyro.start(GYRO_SDA, GYRO_SCL)

  longfill(@acc, 0, 3)
  
  repeat AVG_COUNT
    acc[X] += gyro.ReadX
    acc[Y] += gyro.ReadY
    acc[Z] += gyro.ReadZ

  off[X] := acc[X]/AVG_COUNT
  off[Y] := acc[Y]/AVG_COUNT
  off[Z] := acc[Z]/AVG_COUNT

  longfill(@acc, 0, 3)

  t := cnt + clkfreq/25
  
  repeat

    val[X] := gyro.ReadX - off[X]
    val[Y] := gyro.ReadY - off[Y]
    val[Z] := gyro.ReadZ - off[Z]

    repeat i from 0 to 2
      acc[i] := acc[i] + val[i]
      

    if cnt > t
      t += clkfreq/25
      d.home

      d.dec(val[X]/114)
      d.char(" ")
      d.dec(acc[X]/11400)
      d.chars(" ", 5)
      d.char(13)
       
      d.dec(val[Y]/114)
      d.char(" ")
      d.dec(acc[Y]/11400)
      d.chars(" ", 5)
      d.char(13)
       
      d.dec(val[Z]/114)
      d.char(" ")
      d.dec(acc[Z]/11400)
      d.chars(" ", 5)
      d.char(13)
       
    
    

  